home *** CD-ROM | disk | FTP | other *** search
- Path: vixen.cso.uiuc.edu!usenet
- From: homer@uiuc.edu
- Newsgroups: comp.lang.c++
- Subject: Re: How to convert char to hex in C++?
- Date: 3 Feb 1996 02:09:46 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4eug5a$cp8@vixen.cso.uiuc.edu>
- References: <DM679K.BD1@undergrad.math.uwaterloo.ca>
- Reply-To: n-dade@uiuc.edu
- NNTP-Posting-Host: homer.apr.uiuc.edu
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <DM679K.BD1@undergrad.math.uwaterloo.ca>, hylo@neumann.uwaterloo.ca (Grace Hai Yan Lo) writes:
- > I just wonder if anyone know how to convert a char (e.g. 'a') to
- >hex digit (i.e. 61 for 'a') in C++? Somehow the cout << hex << n <<endl;
- >works for n being an integer but not a character. Thanks.
-
- char n = 'a';
- cout << hex << (int) n << endl;
-
- By casting the char as an int you don't change its numerical value, but the "emit
- an int" method is invoked instead of the "emit a char" method, and the int is
- printed in hexadecimal.
-
- -Nicolas Dade / n9rzb / nicolas-dade@uiuc.edu
-
-